<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<link rel="stylesheet"
	href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css"
	type="text/css" />
<link rel="stylesheet"
	href="/system/libraries/javascript/plupload/js/jquery.ui.plupload/css/jquery.ui.plupload.css"
	type="text/css" />

<script type="text/javascript"
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript"
	src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<script type="text/javascript"
	src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>

<script type="text/javascript"
	src="/system/libraries/javascript/plupload/js/plupload.js"></script>
<script type="text/javascript"
	src="/system/libraries/javascript/plupload/js/plupload.gears.js"></script>
<script type="text/javascript"
	src="/system/libraries/javascript/plupload/js/plupload.silverlight.js"></script>
<script type="text/javascript"
	src="/system/libraries/javascript/plupload/js/plupload.flash.js"></script>
<script type="text/javascript"
	src="/system/libraries/javascript/plupload/js/plupload.browserplus.js"></script>
<script type="text/javascript"
	src="/system/libraries/javascript/plupload/js/plupload.html4.js"></script>
<script type="text/javascript"
	src="/system/libraries/javascript/plupload/js/plupload.html5.js"></script>
<script type="text/javascript"
	src="/system/libraries/javascript/plupload/js/jquery.ui.plupload/jquery.ui.plupload.js"></script>

<!--<script type="text/javascript" src="http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js"></script>-->
<script type="text/javascript">
// Convert divs to queue widgets when the DOM is ready
$(function() {
	
	
	$("#uploader").plupload({
		// General settings
		runtimes : 'html4',
		url : "<?= $base?>upload/uploadImage",
		max_file_size : '1000mb',
		max_file_count: 20, // user can add no more then 20 files at a time
		chunk_size : '1mb',
		unique_names : true,
		multiple_queues : true,
		preinit: attachCallbacks,
		// Resize images on clientside if we can
		resize : {width : 320, height : 240, quality : 90},

		// Rename files by clicking on their titles
		rename: true,

		// Sort files
		sortable: true,

		// Specify what files to browse for
		filters : [
			{title : "Image files", extensions : "jpg,gif,png"}
		]

	
	});

	function attachCallbacks(Uploader) {
		Uploader.bind('FileUploaded', function(Up, File, Response) {
		  if( (Uploader.total.uploaded) == Uploader.files.length)
		  {
			alert('upload has finsihed successfully');
		    window.location = "<?= $base?>upload/saveImages?album_name=<?php 
		    if (isset($album_name)) {
		    	echo $album_name;
		    }
		    ?>";
		  }
		});
	}

	// Client side form validation
	$("#uploader_form").submit(function(e) {
        var uploader = $('#uploader').plupload('getUploader');

        // Files in queue upload them first
        if (uploader.files.length > 0) {
            // When all files are uploaded submit form
            uploader.bind('StateChanged', function() {
                if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                    $("#uploader_form")[0].submit();
                }
            });
                
            uploader.start();
        } else
            alert('You must at least upload one file.');

        return false;
    });



});
</script>
</head>
<body>
	<form style="margin-top: 2%" id=uploader_form  method="post" action="myphpscript.php">
	<?php if (isset($new_album) && new_album == '1') { ?>
		<p>
			Enter the name of the new album: <input type="text" id="album_name" />
		</p>
		<?php }?>
		<div id="uploader"></div>
	</form>

</body>
</html>
